package cn.mvcjava.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class JdbcUtils {
//	数据库的连接池
	private static DataSource dataSource =null;
	
	static { // 静态代码块只被执行一次
		dataSource =new ComboPooledDataSource("mysql");
		
	}
	
//	 获取数据库的连接对象
	public static  Connection getConnection() throws SQLException {
		return dataSource.getConnection();
	} 
	
	
//	数据库关闭连接
	public static void closeConn(Connection conn) {
		if(conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	public static void  rollbackTransation(Connection connection) {
		if(connection!=null) { 
		    try {
				connection.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		    
		}
	}
	
	

}
